package com.example.categoryservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.pojo.dto.CategoryGroupDTO;
import com.example.pojo.dto.CategoryInsertDTO;
import com.example.pojo.dto.CategoryPageQueryDTO;
import com.example.pojo.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.cache.annotation.CacheEvict;

import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
    /**
     * 条件查询图书分类
     *
     * @return
     */
    List<Category> listByQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 根据书名、作者、出版社查询图书分类记录
     *
     * @param categoryGroupDTO
     * @return
     */
    Category selectByGroup(CategoryGroupDTO categoryGroupDTO);

    /**
     * 插入图书分类记录
     *
     * @param categoryInsertDTO
     */
    void insertCategory(CategoryInsertDTO categoryInsertDTO);

    /**
     * 增加库存
     *
     * @param id
     */
    @Update("update tb_category set repertory = repertory + 1 where id = #{id};")
    void plusRepertory(Long id);

    /**
     * 减少库存
     *
     * @param id
     */
    @Update("update tb_category set repertory = repertory - 1 where id = #{id};")
    void decrease(Long id);

    /**
     * 增加库存
     *
     * @param id
     */
    @Update("update tb_category set repertory = repertory + 1 where id = #{id};")
    void plus(Long id);
}
